// pages/calendarMore/calendarMore.js
const api = require('../../utils/api')
const allList = require('../../utils/allList.js')
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nowDate:null,//当前时间
    moreList:[],//热门列表
    listLoding:false,//全屏loading
    morePage:0,//更多列表页码
    isDown:false,//是否到底
    isRefresher:false//是否开启下拉
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      listLoding:true
    })
  },

  //日历加载完成
  handleLoad() {
    this.data.calendarSelect = this.selectComponent('#calendar');
  },
  //修改日历时间
  changeDate(e) {
    if (this.data.calendarSelect)
      this.data.calendarSelect.toggleView('week');
    let date = e.detail.date;
    this.setData({
      nowDate:`${date.year}-${date.month<10 ? '0' + date.month:date.month}-${date.day<10 ? '0'+date.day:date.day}`,
      moreList:[],
      listLoding:true,
      morePage:0,
      isDown:false
    })
    //获取列表
    this.getCalendarMoreList();
  },
  loading(){
    let time = setTimeout(()=>{
      this.setData({
        listLoding:false,
        isRefresher:false
      })
      clearTimeout(time)
    },500)
  },
  //滑动到底部
  scrollDown(e) {
    if( this.data.isDown ) return
    this.setData({
      listLoding:true
    })
    this.data.morePage += 1;
    this.getCalendarMoreList();
  },
  //下拉刷新
  scrollRefresher(){
    this.setData({
      isRefresher:true,
      listLoding:true,
      moreList:[],
      morePage:0,
      isDown:false
    })
    //获取列表
    this.getCalendarMoreList();
  },
  //点击跳转详情页
  onClickMonth(e){
    e.currentTarget.dataset.url = '/pages/calendarDetails/calendarDetails?newsId=' + e.currentTarget.dataset.newsId
    //console.log(e);
    app.toOutLink(e);
  },


  //获取更多列表
  getCalendarMoreList(){
    api.getCalendar({
      "SubTypeName": "",
      "CheckTime":this.data.nowDate,
      "NowPage":this.data.morePage,
      "PageSize":"10",
      "IsHide":"-1",
      "IsTop":"-1",
      "Month":"0"
    }).then(res=>{
      console.log(res)
      if(res.data.code != 0) return
      if(res.data.data.length == 0 ){
        this.setData({
          isDown:true
        })
      } else {
        this.data.moreList = this.data.moreList.concat(res.data.data)
        this.setData({
          moreList:this.data.moreList
        })
      }
      this.loading();
    })
  }

  
})